/**
 * 正则验证 
 */

const utilsTest = {
    /**
     * 是否整型数字
     * @param {number} value 
     * @returns {boolean}
     */
    inNumber(value) {
        var reg = /^[0-9]+$/g;
        return reg.test(value) === false ? false : true;
    },

    /**
     * 是否长度5-12字符的小写英文字符串
     * @param {string} value 
     * @returns {boolean}
     */
    inSmallEnglish(value) {
        var reg = /^[a-z\-]{5,12}$/;
        return reg.test(value) === false ? false : true;
    },

    /**
     * 密码是否长度8-16字符的小写字母+数字
     * @param {string} value 
     * @returns {boolean}
     */
    isPassword(value) {
        var reg = /^(?=.*\d)(?=.*[a-z])[a-z0-9]{8,16}$/;
        return reg.test(value) === false ? false : true;
    },

    /**
     * 是否是邮箱
     * @param {string} value 值
     * @return {boolean}
     */
    isEmail(value) {
        var reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
        return reg.test(value) === false ? false : true;
    },

    /**
     * 是否手机号码
     * @param {string} value 
     * @returns {boolean}
     */
    isPhone(value) {
        var reg = /^1[3456789]\d{9}$/;
        return reg.test(value) === false ? false : true;
    },

    /**
     * 验证域名
     * @param {string} value 值
     * @returns 
     */
    isURL(value) {
        var reg = /^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\*\+,;=]|:|@)|\/|\?)*)?$/i;

        return reg.test(value) === false ? false : true;
    }
}

module.exports = utilsTest;